<template>
  <transition name="dialog-fade">
    <div class="dialog-wrapper" v-show="visible">
      <div class="dialog" :style="{ width: width }">
        <div class="dialog-header">
          <span class="dialog-title">{{ title }}</span>
          <i class="dialog-close" @click="handleClose"></i>
        </div>
        <div class="dialog-body">
          <slot></slot>
        </div>
        <div class="dialog-footer">
          <button @click="handleCancel">取消</button>
          <button @click="handleConfirm">确定</button>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
export default {
  name: 'Dialog',
  props: {
    title: String,
    width: {
      type: String,
      default: '50%'
    },
    visible: Boolean
  },
  methods: {
    handleClose() {
      this.$emit('update:visible', false)
    },
    handleConfirm() {
      this.$emit('confirm')
    },
    handleCancel() {
      this.$emit('cancel')
    }
  }
}
</script>
